﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.ComponentModel;
using System.Globalization;

namespace GoogleMaps
{
	/// <summary>
	/// Describes the position of a control in the map.
	/// </summary>
	public class GControlPosition
	{
		/// <summary>
		/// Initializes a new instance of the GControlPosition class.
		/// </summary>
		public GControlPosition()
		{
			Offset = new GSize();
		}

		/// <summary>
		/// Converts this object to a javascript string.
		/// </summary>
		public string ToJavaScript()
		{
			string anchor = ""; 

			switch (Anchor)
			{
				case GControlAnchor.BottomLeft:
					anchor = "G_ANCHOR_BOTTOM_LEFT";
					break;
				case GControlAnchor.BottomRight:
					anchor = "G_ANCHOR_BOTTOM_RIGHT";
					break;
				case GControlAnchor.TopLeft:
					anchor = "G_ANCHOR_TOP_LEFT";
					break;
				case GControlAnchor.TopRight:
					anchor = "G_ANCHOR_TOP_RIGHT";
					break;
			}

			if (String.IsNullOrEmpty(anchor))
				return String.Empty;

			return String.Format(CultureInfo.InvariantCulture, "new GControlPosition({0}, {1})", anchor, Offset.ToJavaScript());
		}

		/// <summary>
		/// Gets or sets the specific placement of the associated control within the map.
		/// </summary>
		public GControlAnchor Anchor { get; set; }

		/// <summary>
		/// Gest or sets the offset that is used to fine tune the position of the control.
		/// </summary>
		[PersistenceMode(PersistenceMode.InnerProperty), 
		DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public GSize Offset { get; set; }
	}
}
